//
//  PlayLayerUI.cpp
//  AvoidBlock
//
//  Created by 함 우식 on 12. 12. 25..
//
//

#include "PlayLayerUI.h"

using namespace cocos2d;

PlayLayerUI::PlayLayerUI()
{
    _pFCreditCountLabel = CCLabelBMFont::labelWithString("F:0", "adamwarrenpro24.fnt");
    _pFCreditCountLabel->setAnchorPoint(ccp(0.0f, 0.0f));
    _pFCreditCountLabel->setPosition(ccp(150.0f, 400.0f));
    this->addChild(_pFCreditCountLabel, 1);
    
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    
    _pBlind = CCSprite::spriteWithFile("blind.png");
    //CCSize blindSize = blindTexture->getContentSize();
    
    _pBlind->setScaleX(size.width/_pBlind->getScaleX());
    _pBlind->setScaleY(size.height/_pBlind->getScaleY());
    _pBlind->setPosition(ccp(size.width*0.5f, size.height*0.5f));
    _pBlind->setOpacity(70);
    _pBlind->setVisible(false);
    this->addChild(_pBlind, 1);
    
    _pMenu = CCMenu::menuWithItems(NULL);
    _pMenu->setPosition(ccp(0.0f, 0.0f));
    this->addChild(_pMenu, 2);
    
    CCMenuItemImage* pMenuItem;
    
    pMenuItem = CCMenuItemImage::create(
                                        "restart_btn.png",
                                        NULL,
                                        this,
										menu_selector(PlayLayerUI::retry) );
	pMenuItem->setPosition( ccp(size.width * 0.5f, size.height * 0.24f) );
    _pMenu->addChild(pMenuItem);
    
    pMenuItem = CCMenuItemImage::create(
                                        "main_btn.png",
                                        NULL,
                                        this,
                                        menu_selector(PlayLayerUI::moveMenuScene) );
	pMenuItem->setPosition( ccp(size.width * 0.5f, size.height * 0.12f) );
    _pMenu->addChild(pMenuItem);


    _pMenu->setVisible(false);
    
    _pScoreBoard = new PlayLayerUIScoreBoard();
    _pScoreBoard->setPosition(ccp(size.width*0.5f, size.height*0.5f));
    _pScoreBoard->setVisible(false);
    this->addChild(_pScoreBoard, 2);
    
}

void PlayLayerUI::setFCreditCount(int count)
{
    CCString* pStr = CCString::stringWithFormat("F:%d",count);
    _pFCreditCountLabel->setString(pStr->getCString());
}

void PlayLayerUI::showResultWindow()
{
    _pBlind->setVisible(true);
    _pMenu->setVisible(true);
    _pScoreBoard->setVisible(true);
}

void PlayLayerUI::retry(CCObject* pSender)
{
    Controller::runScene(PLAY_SCENE);
}

void PlayLayerUI::moveMenuScene(CCObject* pSender)
{
    Controller::runScene(MENU_SCENE);
}